﻿Imports System.Data.SqlClient
Public Class Frm_Tabligh
    Dim isDateValidate As Boolean = True
    Dim isDateValidate2 As Boolean = True
    Dim pourDate As Date
    Dim deMofa As DictionaryEntry

    'Remplissage des zone de la form
    Public Sub remplirZone()
        If Frm_a7kam.avo.remplir_Info() Then
            With Frm_a7kam.avo.tabligh
                txtNumTabligh.Text = .numInfor
                If .dureeDappel <> 0 Then
                    txt_DureeDappel.Text = .dureeDappel
                End If
                If .dteInscripTribu.Date.Date <> CDate("01/01/0001") Then
                    TextBox1.Text = .dteInscripTribu
                End If

                If .dteInfor.Date.Date <> CDate("01/01/0001") Then
                    dteInfor.Text = .dteInfor
                End If

                TxtObserv.Text = .observation
                'Partager.moi.remplir_List_mofawad()
                'Dim i As Integer = 0
                
            End With
            ' Partager.moi.List_mofawad.Clear()
        End If
    End Sub

    Private Sub Frm_Tabligh_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_a7kam.Enabled = True
    End Sub
    Private Sub Frm_Tabligh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtNumTabligh.Select()

        remplirZone()

        txtnumDec.Text = Frm_a7kam.avo.Num_decision
    End Sub

    Private Sub btnAjouter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAjouter.Click
        Try
            If Not Frm_a7kam.avo.remplir_Info() Then ' si la decision n'a pas d'information
                If txtNumTabligh.Text <> "" And isDateValidate And isDateValidate2 Then
                    If TextBox1.Text = "  /  /" Then
                        pourDate = Nothing
                    Else
                        pourDate = TextBox1.Text
                    End If

                    If MsgBox("هل تريد فعلا إضافة هذاالتبليغ ؟", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "إضافة") = MsgBoxResult.Yes Then
                        With Frm_a7kam.avo.tabligh
                            .numInfor = txtNumTabligh.Text
                            .dteInscripTribu = pourDate

                            If dteInfor.Text = "  /  /" Then
                                pourDate = Nothing
                            Else
                                pourDate = dteInfor.Text
                            End If
                            .dteInfor = pourDate

                            If txt_DureeDappel.Text <> "" Then
                                .dureeDappel = CByte(txt_DureeDappel.Text)
                            Else
                                .dureeDappel = Nothing
                            End If
                            .observation = TxtObserv.Text
                        End With
                        Frm_a7kam.avo.Ajouter_Info()
                        remplirZone()
                        MsgBox("تم الإضافة بنجاح", MsgBoxStyle.Information, "نجاح")
                    End If
                Else
                    MsgBox("لم تدخل رقم التبليغ أو التاريخ خاطئ", MsgBoxStyle.Critical, "خطأ")
                End If
            Else
                MsgBox("هذا الحكم لديه تبليغ", MsgBoxStyle.Critical, "خطأ")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnmodifier_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodifier.Click
        Try

        
        If Frm_a7kam.avo.remplir_Info() Then
            If TextBox1.Text = "  /  /" Then
                isDateValidate = True
            End If

            If dteInfor.Text = "  /  /" Then
                isDateValidate2 = True
            End If


            If txtNumTabligh.Text <> "" And isDateValidate And isDateValidate2 Then
                If MsgBox("هل تريد فعلا تعديل هذاالتبلغ ؟", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "تعديل") = MsgBoxResult.Yes Then

                    If TextBox1.Text = "  /  /" Then
                        pourDate = Nothing
                    Else
                        pourDate = TextBox1.Text
                    End If


                    With Frm_a7kam.avo.tabligh
                        .dteInscripTribu = pourDate
                        .numInfor = txtNumTabligh.Text
                        If dteInfor.Text = "  /  /" Then
                            pourDate = Nothing
                        Else
                            pourDate = dteInfor.Text
                        End If

                        .dteInfor = pourDate

                        If txt_DureeDappel.Text <> "" Then
                            .dureeDappel = CByte(txt_DureeDappel.Text)
                        Else
                            .dureeDappel = Nothing
                        End If
                        .observation = TxtObserv.Text
                    End With
                    Frm_a7kam.avo.modifier_Info()
                    remplirZone()
                    MsgBox("تم تعديل بنجاح", MsgBoxStyle.Information, "نجاح")
                End If
            Else
                MsgBox("لم تدخل رقم التبليغ أو التاريخ خاطئ", MsgBoxStyle.Critical, "خطأ")
            End If
        Else
            MsgBox("هذا الحكم أو القرار ليس له أي تبليغ", MsgBoxStyle.Critical, "خطأ")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnSupprimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSupprimer.Click
        Try
            If Frm_a7kam.avo.remplir_Info Then
                If MsgBox("هل تريد فعلا حذف هذا التبليغ؟", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "حذف") = MsgBoxResult.Yes Then
                    Partager.close()
                    Frm_a7kam.avo.suprimmer_Info()
                    Partager.vider(Me)
                    MsgBox("تم الحذف بنجاح", MsgBoxStyle.Information, "الحذف")
                    isDateValidate = True
                    isDateValidate2 = True
                End If
            Else
                MsgBox("هذا الحكم أو القرار ليس له أي تبليغ", MsgBoxStyle.Critical, "خطأ")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Private Sub dteInfor_TypeValidationCompleted(ByVal sender As Object, ByVal e As TypeValidationEventArgs) Handles dteInfor.TypeValidationCompleted
        If (Not e.IsValidInput) Then
            If dteInfor.Text <> "  /  /" Then
                Me.ToolTip1.ToolTipTitle = "تارخ خاطئ !"
                Me.ToolTip1.Show("أدخل التاريخ على هذا الشكل: السنة/الشهر/اليوم", Me.dteInfor, 0, 40, 5000)
                isDateValidate2 = False
            End If
            If dteInfor.Text = "  /  /" Then
                isDateValidate2 = True
            End If
        Else
            isDateValidate2 = True
        End If
    End Sub

    Private Sub TextBox1_TypeValidationCompleted(ByVal sender As Object, ByVal e As TypeValidationEventArgs) Handles TextBox1.TypeValidationCompleted
        If (Not e.IsValidInput) Then
            If TextBox1.Text <> "  /  /" Then
                Me.ToolTip1.ToolTipTitle = "تارخ خاطئ !"
                Me.ToolTip1.Show("أدخل التاريخ على هذا الشكل: السنة/الشهر/اليوم", Me.TextBox1, 0, -50, 5000)
                isDateValidate = False
            End If

            If TextBox1.Text = "  /  /" Then
                isDateValidate = True
            End If
        Else
            isDateValidate = True
        End If
    End Sub

    Private Sub txtNumTabligh_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumTabligh.KeyPress
        Dim allowedChars As String = "1234567890/"
        If e.KeyChar = ChrW(8) Then
            e.Handled = False
        ElseIf allowedChars.IndexOf(e.KeyChar) = -1 Then
            ' Invalid Character
            e.Handled = True
        End If
    End Sub

    Private Sub txt_DureeDappel_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt_DureeDappel.KeyPress
        Dim allowedChars As String = "1234567890/"
        If e.KeyChar = ChrW(8) Then
            e.Handled = False
        ElseIf allowedChars.IndexOf(e.KeyChar) = -1 Then
            ' Invalid Character
            e.Handled = True
        End If
    End Sub
End Class